package admin

import (
	"backend_api/internal/model/request"
	"backend_api/internal/service"
	"github.com/gin-gonic/gin"
)

type AdminToolsCategory struct{}

// GetToolCategoryList 获取分类列表
func (h *AdminToolsCategory) GetToolCategoryList(c *gin.Context) {
	var req request.ToolCategoryListReq
	if err := c.ShouldBindQuery(&req); err != nil {
		ResponseError(c, err)
		return
	}
	srv := service.ToolCategoryService{}
	list, total, err := srv.GetToolCategoryList(&req)
	if err != nil {
		ResponseError(c, err)
		return
	}

	ResponseSuccess(c, gin.H{
		"list":  list,
		"total": total,
	})
}

// AddToolCategory 添加分类
func (h *AdminToolsCategory) AddToolCategory(c *gin.Context) {
	var req request.ToolCategoryAddReq
	if err := c.ShouldBindJSON(&req); err != nil {
		ResponseError(c, err)
		return
	}

	srv := service.ToolCategoryService{}
	if err := srv.AddToolCategory(&req); err != nil {
		ResponseError(c, err)
		return
	}

	ResponseSuccess(c, nil)
}

// UpdateToolCategory 更新分类
func (h *AdminToolsCategory) UpdateToolCategory(c *gin.Context) {
	var req request.ToolCategoryUpdateReq
	if err := c.ShouldBindJSON(&req); err != nil {
		ResponseError(c, err)
		return
	}
	srv := service.ToolCategoryService{}

	if err := srv.UpdateToolCategory(&req); err != nil {
		ResponseError(c, err)
		return
	}

	ResponseSuccess(c, nil)
}

// DeleteToolCategory 删除分类
func (h *AdminToolsCategory) DeleteToolCategory(c *gin.Context) {
	var req request.ToolCategoryDeleteReq
	if err := c.ShouldBindJSON(&req); err != nil {
		ResponseError(c, err)
		return
	}
	srv := service.ToolCategoryService{}
	if err := srv.DeleteToolCategory(&req); err != nil {
		ResponseError(c, err)
		return
	}

	ResponseSuccess(c, nil)
}
